
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
 */
package myframework;

//~--- non-JDK imports --------------------------------------------------------

import nac.firefight.AbstractGameState;
import mdes.slick.animation.Timeline;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.gui.AbstractComponent;
import org.newdawn.slick.state.StateBasedGame;

//~--- JDK imports ------------------------------------------------------------

import java.util.ArrayList;
import java.util.List;
import nac.firefight.FireFightGame;

/**
 *
 * @author nac/ for gui. I guess.
 */
public abstract class PassiveGameState extends AbstractGameState {
    protected List<AbstractComponent> components = null;
    protected List<Timeline>          timelines  = null;

    public PassiveGameState(int id, FireFightGame ffg) {
        super(id, ffg);
        this.components = new ArrayList();
        this.timelines  = new ArrayList();
    }

    public List<AbstractComponent> getComponents() {
        return components;
    }

    public AbstractComponent getComponent(int index) {
        return (AbstractComponent) components.get(index);
    }

    public void addComponent(int index, AbstractComponent element) {
        components.add(index, element);
    }

    public boolean addComponent(AbstractComponent e) {
        return components.add(e);
    }

    public List<Timeline> getTimelines() {
        return timelines;
    }

    public Timeline getTimeline(int index) {
        return (Timeline) timelines.get(index);
    }

    public void addTimeline(int index, Timeline tl) {
        timelines.add(index, tl);
    }

    public boolean addTimeline(Timeline tl) {
        return timelines.add(tl);
    }

    protected void preUpdate(GameContainer container, StateBasedGame game, int delta) {}

    protected void postUpdate(GameContainer container, StateBasedGame game, int delta) {}

    protected void preRender(GameContainer container, StateBasedGame game, Graphics g) {}

    protected void postRender(GameContainer container, StateBasedGame game, Graphics g) {}

    public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException {
        preUpdate(container, game, delta);

        for (int i = 0; i < timelines.size(); i++) {
            Timeline tl = timelines.get(i);

            tl.update(delta);
        }

        postUpdate(container, game, delta);
    }

    public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
        preRender(container, game, g);

        for (int i = 0; i < components.size(); i++) {
            AbstractComponent ac = components.get(i);

            ac.render(container, g);
        }

        postRender(container, game, g);
    }
}


//~ Formatted by Jindent --- http://www.jindent.com
